%{
#include <iostream>
#include <map>
#include "declarations.h"
#include "parser.hpp"
using namespace std;
int lineNumber = 1;
%}

%%
[ \t]				;
"//".*\n			;  { lineNumber++; }
("/*"(.|\n)*"*/")	;
("/*"(.^"*/"|\n)*)	{ printf("Bad commentary\n"); yyterminate();}
"void"			{ return VOID; }
"int"			{ return INT; }
"double"		{ return DOUBLE; }	
"bool"			{ return BOOL; }
"string"		{ return STRING; }
"null"			{ return INULL; }
"while"			{ return WHILE; }
"for"			{ return FOR; }
"if"			{ return IF; }
"else"			{ return ELSE; }
"return"		{ return RETURN; }
"break"			{ return BREAK; }
"print"			{ return PRINT; }
"readint"		{ return READINT; }
"readline"		{ return READLINE; }
"true"			{ return TRUE; }
"false"			{ return FALSE; }
("0x"|"0X")[a-fA-F0-9]+			{ return CHEX; }
[0-9]+			{ yylval.values.value.decimal_value = atoi(yytext); return CDEC; }
[+-]?[0-9]+\.[0-9]*([eE]([+-][0-9]+)?)?	{ yylval.values.value.double_value = atof(yytext); return CDOUBLE; }
([a-zA-Z]([0-9a-zA-Z_])*){1,31}		{ strcpy(yylval.values.name, yytext); return ID; }
\".*\"			{ return CSTRING; }
\"(.|\n)*\"		{ printf("Bad string\n"); yyterminate();}
"+"				{ return '+'; }
"-"				{ return '-'; }
"*"				{ return '*'; }
"/"				{ return '/'; }
"%"				{ return '%'; }
"<"				{ return '<'; }
"<="			{ return LESSEQTHAN; }
">"				{ return '>'; }
">="			{ return MOREEQTHAN; }
"="				{ return '='; }
"=="			{ return EQUALCOMP;}
"!="			{ return DIFFCOMP; }
"&&"			{ return AND; }
"||"			{ return OR; }
"!"				{ return '!'; }
";"				{ return ';'; }
","				{ return ','; }
"["				{ return '['; }
"]"				{ return ']'; }
"("				{ return '('; }
")"				{ return ')'; }
"{"				{ return '{'; }
"}"				{ return '}'; }
\n				; { lineNumber++; }
.				; { printf("Unknown token\n"); yyterminate(); }
%%



